package trading.ctm.yunjing.module.message.activity

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import cc.vv.baselibrary.activity.BaseActivity
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.baselibrary.view.LKDialog
import cc.vv.baselibrary.view.imgselector.utils.LKPermissionUtil
import cc.vv.lkbasecomponent.util.LKStringUtil
import kotlinx.android.synthetic.main.activity_message_inform.*
import trading.ctm.yunjing.R
import trading.ctm.yunjing.module.message.adapter.MessageAdapter

/**
 * @desc 消息通知
 * @author zouxiaorui
 * @date  2018/8/8
 */
class MessageInformActivity : BaseActivity() {

    override fun initLayoutRes(): Int {
        return R.layout.activity_message_inform
    }

    override fun initView(bundle: Bundle?) {
        super.initView(bundle)

    }

    override fun initAction(data: Bundle?) {
        super.initAction(data)

        var data = listOf("ooooooooooooooooo", "ooooooooooooooooo", "ooooooooooooooooo")
        rv_ami_message_list.layoutManager = LinearLayoutManager(this)
        var adapter = MessageAdapter(R.layout.adapter_message_inform, data)
        rv_ami_message_list.adapter = adapter

        adapter.setOnItemClickListener { adapter, view, position ->
            startActivity(Intent(this@MessageInformActivity, MessageActivity::class.java))
        }


        btbv_ami_inform_title.setEventInterface(object : BaseTopBarView.EventInterface {
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {
            }

            override fun rightOnClick() {

                val dialog = LKDialog(this@MessageInformActivity)
                dialog.setTitle("拨打客服电话")
                dialog.setMessage("4008001234")
                dialog.setCanceledOnTouchOutside(true)
                dialog.setRightButton("确定") {
                    val hasPermission = LKPermissionUtil.getInstance().requestCallPhone(this@MessageInformActivity)
                    if (hasPermission) {
                        callPhone("4008001234")
                    } else {
                    }
                    dialog.dismiss()
                }
                dialog.setLeftButton("取消") { dialog.dismiss() }
                dialog.show()
            }

        })
    }

    /**
     * 点击手机号时拨打电话
     *
     * @param phoneNum 手机号
     */
    @SuppressLint("MissingPermission")
    fun callPhone(phoneNum: String) {
        val intent = Intent(Intent.ACTION_CALL)
        val data = Uri.parse("tel:$phoneNum")
        intent.data = data
        startActivity(intent)
    }

}